package cn.com.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;

import cn.com.domain.Person;


@Service
public class PersonService {
	private static Map<Integer,Person> map = new HashMap<Integer, Person>();	
	private static Integer id = 0;												
	
	static{
		for(int i=0;i<10;i++){
			Person p = new Person();
			p.setId(id++);
			p.setName("tony"+i);
			p.setAge(10+i);
			
			map.put(i, p);
		}
	}
	

	public List<Person> findAll(){
		return new ArrayList(map.values());			
	}
	
	//新增
		public void insert(Person p){
			id++;
			p.setId(id);
			
			map.put(id, p);
		}
		
		//获得一个记录
		public Person get(Integer id){
			return map.get(id);
		}
		
		//修改
		public void update(Person p){
			map.put(p.getId(), p);
		}
		
		//删除单条
		public void deleteById(Integer id){
			map.remove(id);
		}

	
	

}
